<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>

	<style type="text/css">
	li{list-style: none;}</style>
</head>
<body>
<ul id="lis">
<li><input type="button" value="-"  /><strong>0</strong><input type="button" value="+"  />单价：<em>12.50</em>元  小计：<span>0.00</span>元</li>
<li><input type="button" value="-"  /><strong>0</strong><input type="button" value="+"  />单价：<em>17.50</em>元  小计：<span>0.00</span>元</li>
<li><input type="button" value="-"  /><strong>0</strong><input type="button" value="+"  />单价：<em>10.00</em>元  小计：<span>0.00</span>元</li>
<li><input type="button" value="-"  /><strong>0</strong><input type="button" value="+"  />单价：<em>19.00</em>元  小计：<span>0.00</span>元</li>

</ul>
<script type="text/javascript">
var aCountList=document.getElementsByTagName("strong");//抓strong节点
var aPriceList=document.getElementsByTagName("em");//抓em节点
var asubtotalList=document.getElementsByTagName("span");//抓span节点

//定义数字
var aCount=[];
var aPrice=[];
var aSubtotal=[];

// //数量
// var count=parseInt(oCount.innerHTML);
// console.log(count);
// var price=parseFloat(oPrice.innerHTML);
// console.log(price);
// var subtotal=(parseFloat(osubtotal.innerHTML)).toFixed(2);
// console.log(subtotal);
var oUL=document.getElementById("lis");

var aInputList=oUL.getElementsByTagName("input");
console.log(aInputList);
var currentNo=-1;

for (var i = 0; i <aInputList.length; i+=2) {
  aInputList[i].index=i/2;
  aInputList[i+1].index=i/2;
  aInputList[i].onclick=function(){       
    stotal(this.index,"-");
  }

    aInputList[i+1].onclick=function(){
    
    stotal(this.index,"+");
    
  }

}

   function stotal(currentNo,char){
    aCount[currentNo]=parseInt(aCountList[currentNo].innerHTML);
    
    if(char=="-"){
          aCount[currentNo]--;
          if(aCount[currentNo]<0) aCount[currentNo]=0;
    }
    else {
          aCount[currentNo]++;
    }
    aCountList[currentNo].innerHTML=aCount[currentNo];
    aPrice[currentNo]=parseFloat(aPriceList[currentNo].innerHTML);
    aSubtotal[currentNo]=(aCount[currentNo]*aPrice[currentNo]).toFixed(2);    //toFixed输出数字限制两位小数
    asubtotalList[currentNo].innerHTML=aSubtotal[currentNo];

   }


// oInputAdd.onclick=function(){
//  count++;
//  oCount.innerHTML=count;
//  subtotal=(price*count).toFixed(2);
//  osubtotal.innerHTML=subtotal;
// }

// oInputSubrtact.onclick=function(){
//   count--;
//   if(count<0){
//    count=0;
//  }
//    oCount.innerHTML=count;
//    subtotal=(price*count).toFixed(2);
//    osubtotal.innerHTML=subtotal;
// }





</script>
</body>
</html>